/*
 ------------------------------------------------------------------------------
 Copyright (C) 2006-2007 Team Blur.

 This file is part of the Quantum Engine source code.

 The Quantum Engine source code is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or (at your
 option) any later version.

 The Quantum Engine source code is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 more details.

 You should have received a copy of the GNU General Public License along with
 the Quantum Engine source code; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 ------------------------------------------------------------------------------
*/


#ifndef __FRAMEWORK_CVARSYSTEM_H__
#define __FRAMEWORK_CVARSYSTEM_H__


typedef enum {
	CVAR_ARCHIVE					= BIT(0),	// Set to cause it to be saved to a config file
	CVAR_USERINFO					= BIT(1),	// Added to user info when changed
	CVAR_SERVERINFO					= BIT(2),	// Added to server info when changed
	CVAR_INIT						= BIT(3),	// Can only be set from the command line
	CVAR_ROM						= BIT(4),	// Cannot be set by user at all
	CVAR_CHEAT						= BIT(5),	// Cannot be set when cheats are disabled
	CVAR_LATCH						= BIT(6)	// Save changes until restart
} cvarFlags_t;

// Nothing outside the CVar_*() functions should modify these fields!
typedef struct cvar_s {
	const char *			name;
	const char *			value;				// Current value
	const char *			resetValue;			// Initial value
	const char *			latchedValue;		// Latched value
	float					floatValue;			// Value converted to float
	int						integerValue;		// Value converted to integer

	int						flags;
	const char *			description;

	bool					modified;			// Set each time the variable is changed

	struct cvar_s *			next;
	struct cvar_s *			nextHash;
} cvar_t;

/*
 ==============================================================================

 FUNCTIONS EXPORTED BY THE ENGINE

 ==============================================================================
*/

typedef struct {
	// Creates the variable if it doesn't exist, or returns the existing one.
	// If the variable exists, the flags will be OR'ed in, and if it has a
	// latched value, the current value will be updated. If the variable has
	// the CVAR_ROM flag set, the current value will be forced to the specified
	// value. Both the reset value and the description will be updated.
	// The description parameter can be NULL if you don't want it.
	cvar_t *				(*Get)(const char *name, const char *value, int flags, const char *description);

	// Sets the value of a variable
	void					(*SetString)(cvar_t *cvar, const char *value);
	void					(*SetFloat)(cvar_t *cvar, float value);
	void					(*SetInteger)(cvar_t *cvar, int value);

	// Finds a variable with the given name. Returns NULL if not found.
	cvar_t *				(*FindVariable)(const char *name);

	// Gets the value of a variable by name. Returns an empty string or zero if
	// it doesn't exist.
	const char *			(*GetVariableString)(const char *name);
	float					(*GetVariableFloat)(const char *name);
	int						(*GetVariableInteger)(const char *name);

	// Sets the value of a variable by name. Creates the variable if it doesn't
	// exist.
	void					(*SetVariableString)(const char *name, const char *value);
	void					(*SetVariableFloat)(const char *name, float value);
	void					(*SetVariableInteger)(const char *name, int value);

	// Returns true if cheats are allowed, false otherwise
	bool					(*AllowCheats)(void);

	// Gets flags that tell what kind of variables have been modified
	int						(*GetModifiedFlags)(void);

	// Sets flags that tell what kind of variables have been modified
	void					(*SetModifiedFlags)(int flags);

	// Clears flags to allow detecting another modification to variables
	void					(*ClearModifiedFlags)(int flags);
} odCVarSystem_t;


#endif	// __FRAMEWORK_CVARSYSTEM_H__
